package top.kikt.book.util

import okhttp3.Cookie
import okhttp3.CookieJar
import okhttp3.HttpUrl
import java.util.*
import kotlin.collections.ArrayList

class MyCookieJar : CookieJar {

    private val map = Collections.synchronizedMap(HashMap<String, ArrayList<Cookie>>())

    override fun loadForRequest(url: HttpUrl): List<Cookie> {
        return map[url.host] ?: emptyList()
    }

    override fun saveFromResponse(url: HttpUrl, cookies: List<Cookie>) {
        map[url.host] = ArrayList(cookies)
    }
}